package com.rjgc.title.controller.user;

import com.rjgc.title.common.result.Result;
import com.rjgc.title.model.entity.user.CurrentTitle;
import com.rjgc.title.model.entity.user.LearningSociology;
import com.rjgc.title.service.CurrentTitleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: title-parent
 * @author: Mr.Zhuo
 * @create: 2022-04-26 18:21
 **/
@Api(tags = "现任职称：")
@RestController
@RequestMapping("/api/currentt")
public class CurrentTitleController {

    @Autowired
    private CurrentTitleService currentTitleService;

    /**
     * 根据id查询
     * @param
     * @return
     */
    @GetMapping("inner/getByUserId")
    public Result getById(HttpServletRequest request) {
        String userId = (String) request.getSession().getAttribute("userId");
        // 调用service方法进行查询
        List<CurrentTitle> currentTitles=currentTitleService.getByUserId(userId);

        // 返回数据
        return Result.ok(currentTitles);
    }


    /**
     * 保存 或者更新
     * @param request
     * @param currentTitle
     * @return
     */
    @PostMapping("inner/save")
    public Result save(HttpServletRequest request, @RequestBody CurrentTitle currentTitle) {
        // 获取当前对象的id
        String userId = (String) request.getSession().getAttribute("userId");
        currentTitle.setUserId(Long.parseLong(userId));
        // 调用service方法进行保存
        currentTitleService.saveCurrentTitle(currentTitle);
        return Result.ok();
    }
}
